
package com.wiesloch.controller;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

/**
 * <p>ClassName:HomeController</p>
 * <p>Description:</p>
 * <p> E-mail:jintao_iknow@163.com </p>
 * Date:     2016年5月11日 下午5:01:12 <br/>
 * @author   tao95
 * @version  1.0
 * @since    JDK 1.7
 *
 */
@Controller
@RequestMapping("home")
public class HomeController {
	
	@RequestMapping(value="/index",method = { RequestMethod.POST, RequestMethod.GET })
	public ModelAndView index() throws Exception {
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("/home/index");
		return modelAndView;
	}
	@RequestMapping(value="/left",method = { RequestMethod.POST, RequestMethod.GET })
	public ModelAndView left() throws Exception {
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("/home/left");
		return modelAndView;
	}
	@RequestMapping(value="/top",method = { RequestMethod.POST, RequestMethod.GET })
	public ModelAndView top() throws Exception {
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("/home/top");
		return modelAndView;
	}
	@RequestMapping(value="/right",method = { RequestMethod.POST, RequestMethod.GET })
	public ModelAndView right() throws Exception {
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("/home/right");
		return modelAndView;
	}
	@RequestMapping(value="/logout",method = { RequestMethod.POST, RequestMethod.GET })
	public ModelAndView logout(HttpServletRequest request) throws Exception {
		
		ModelAndView modelAndView = new ModelAndView();
		request.getSession().invalidate();
		
		String val = null;
		Cookie cookies[] = request.getCookies();
		if (cookies != null) {
			for (Cookie cookie : cookies) {
				if ("loginName1111".equals(cookie.getName())) {
					cookie.setValue(null);
					break;
				}
			}
		}
		modelAndView.setViewName("distributor/login");
		return modelAndView;
	}
}
